package homework1;

import java.sql.SQLException;
import java.sql.Statement;

public class Card 
{
	public static int createYearCard(String name)//创建年卡，返回正数表示用户id，否则为错误码
	{
		int userID=(User.getUserID(name));
		if(userID<=0) return 0;
		try 
		{
			Statement stmt = DataBaseController.getDBConnecter().connection.createStatement();
			String sql="INSERT INTO CARD (CARD_TYPE, OPEN_DATE, OWNER_ID,LAST_TIME) VALUES ('1', curdate(),'"+userID+"','0')";
			boolean rs=stmt.execute(sql);
			return userID;
		} catch (SQLException e) 
		{
			e.printStackTrace();
			return -1;
		} 
	}
	
	public static int createTimesCard(String name,int times)//创建次卡，返回正数表示用户id，否则为错误码
	{
		int userID=(User.getUserID(name));
		if(userID<=0) return 0;
		try 
		{
			Statement stmt = DataBaseController.getDBConnecter().connection.createStatement();
			String sql="INSERT INTO CARD (CARD_TYPE, OPEN_DATE, OWNER_ID,LAST_TIME) VALUES ('2', curdate(),'"+userID+"','"+times+"')";
			boolean rs=stmt.execute(sql);
			return userID;
		} catch (SQLException e) 
		{
			e.printStackTrace();
			return -1;
		} 
	}
	
	public static String getCreateCardWrong(int id)//获取建卡出错信息
	{
		return "不存在的用户名";
	}
}
